#include <iostream>
#include "BinaryTree.h"

// 99.97 %
class Solution
{
  public:
	bool isSymmetric(TreeNode *root)
	{
		if (!root)
			return true;
		return Symmetric(root->left, root->right);
	}
	bool Symmetric(TreeNode *left, TreeNode *right)
	{
		if (!left && !right)
			return true;
		if (!left || !right)
			return false;
		if (left->val == right->val)
		{
			return (Symmetric(left->left, right->right) && Symmetric(right->left, left->right));
		}
		return false;
	}
};

using namespace std;
int main()
{
	int arr[] = {1, 2, 0, 0, 0};
	int n = sizeof(arr) / sizeof(arr[0]);
	TreeNode *tree = createBinaryTree(arr, n);
	preorderPrint(tree);
	cout << endl;
	cout << Solution().isSymmetric(tree) << endl;
	return 0;
}
